package com.webcamtracker.ms2;

/**
 * precalcular bin index from color
 *
defines member variables and functions that store and manipulate the color histogram distribution of an area in a video image.
 */
public class ColorHistogramIndex {
    // rgb color histogram
    public float[][][] rgbHistogram;

    public int width;
    public int height;
    public int numberOfBins;
    public float[][] weights;

    //bin indexes
    public int[][] redBinIndex;
    public int[][] greenBinIndex;
    public int[][] blueBinIndex;

    public ColorHistogramIndex(int width, int height, int numberOfBins) {
        this.width = width;
        this.height = height;
        this.numberOfBins = numberOfBins;
        rgbHistogram = new float[numberOfBins][numberOfBins][numberOfBins];
        redBinIndex = new int[height][width];
        greenBinIndex = new int[height][width];
        blueBinIndex = new int[height][width];
        weights = new float[height][width];
    }

    public void clearRGBHistrogram() {
        for (int i = 0; i < rgbHistogram.length; i++) {
            for (int j = 0; j < rgbHistogram[i].length; j++) {
                for (int k = 0; k < rgbHistogram[i][j].length; k++) {
                    rgbHistogram[i][j][k] = 0;
                }
            }
        }
    }

    public void initializeBinIndexes() {
        for (int i = 0; i < redBinIndex.length; i++) {
            for (int j = 0; j < redBinIndex[i].length; j++) {
                redBinIndex[i][j]=0;
                greenBinIndex[i][j]=0;
                blueBinIndex[i][j]=0;
            }
        }
    }

    public void initializeWeights() {
        for (int i = 0; i < weights.length; i++) {
            for (int j = 0; j < weights[i].length; j++) {
                weights[i][j]=0.0f;
            }
        }
    }

    public float[][][] getRgbHistogram() {
        return rgbHistogram;
    }
}
